package com.bjpowernode.springboot.web;
import com.bjpowernode.springboot.domain.IPage;
import com.bjpowernode.springboot.domain.User ;


import com.bjpowernode.springboot.service.TestService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/user")
public class TestController {

    @Autowired
    TestService testService;

    @ApiOperation(value = "根据ID查询")
    @GetMapping("/get")
    public User getTestById(@RequestParam int id){
        return this.testService.selectByPrimaryKey(id);
    }

    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public int insert(@RequestBody User record){
        return this.testService.insert(record);
    }
    //boolean removeById(Serializable id);
    @ApiOperation(value = "新增CC")
    @PostMapping("/savese")
    public int insertSelective(@RequestBody User record){
        return this.testService.insertSelective(record);
    }

    @ApiOperation(value = "删除")
    @PatchMapping("/delete")
    public int delete(@RequestParam int id) {
        return this.testService.deleteByPrimaryKey(id);
    }
    @ApiOperation(value = "修改")
    @PutMapping("/update")
    public int update(@RequestParam User record) {
        return this.testService.updateByPrimaryKey(record);
    }

    public ArrayList<User> goods=new ArrayList<>();
    //一页的用户

    @GetMapping ("/pagehelper")
    @ResponseBody
    public List<User> pageHelperController(int page, int size) {
        return testService.personService(page, size);
    }

//    @Autowired
//    UserRespository userRespository;
//    @PostMapping("/addUser")
//    public void addUser(User user){
//        userRespository.save(user);
//    }


}
